/*
 *说明：选择时间策略脚本
 *
 *@author liuxun 2012-03-19
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		title: '时间策略列表(双击选定记录行)',
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[
		    
		    {title:'时间策略名称',field:'time_policy_name',align:'center',width:80},

		    {title:'开始日期',field:'start_date',align:'center',width:80},

		    {title:'结束日期',field:'end_date',align:'center',width:80},
		            
		    {title:'开始时间',field:'start_time',align:'center',width:80},
		         
		    {title:'结束时间',field:'end_time',align:'center',width:80},

		    {title:'星期',field:'week',align:'center',width:80,
            	formatter:function(value, res){
            		var str = '';  
            		var arr = value.split("");//全部分割   
            		for (i = 0; i < arr.length; i++) {
            			var j = i;
            			   if(arr.length==j+1){
            				   str += arr[i];
            			   }else{
            				   str += arr[i] +'、' ;
            			   }
            		}
            		return str;
            	}		    	
		    },

		    {title:'时间策略描述',field:'time_policy_desc',align:'center',width:80}
        ]],
		pagination:true,
		singleSelect: true,
		onDblClickRow: function(rowIndex, rowData) {
	    	window.returnValue = rowData;
	    	window.close();
	    }
	});

	queryOperation();
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'D_TIME_POLICY!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}